<?php
namespace Plu\Library\Models\Platform\Reports;

use Phalcon\Mvc\Model;

class ReportDailyRoomContribution extends Model {
    public $Id;

    public $Day;

    public $RoomId;

    public $Count;

    public function initialize() {
        $this->setReadConnectionService('db.report.slave');
    }

    public function getSource() {
        return "ReportDailyRoomContribution";
    }

    /**
     * 获取指定房间的魅力值
     */
    static public function getContributions($roomIds, $startTime, $endTime) {
        if (empty($roomIds)) {
            return false;
        }

        $sql = array();
        $len = count($roomIds);
        $params = array(
            'startTime' => $startTime,
            'endTime'   => $endTime
        );

        for ($c = 0; $c < $len; $c++) {
            $p = "r{$c}";
            $sql[] = " RoomId = :{$p}: ";
            $params[$p] = $roomIds[$c];
        }
        $sql = '(' . join(' OR ', $sql) . ')';

        $items = self::sum(array(
            "conditions" => "Day >= :startTime: AND Day <= :endTime: AND " . $sql,
            "column"     => "Count",
            "group"      => "RoomId",
            "order"      => "sumatory DESC",
            "bind"       => $params
        ));

        return $items->toArray();
    }
}
?>
